package com.jjh.controller;

import com.jjh.consts.Result;
import com.jjh.pojo.vo.TaocanVo;
import com.jjh.service.TaoCanService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 套餐控制器类
 */
@RestController
@RequestMapping("/api/taocan")
public class TaoCanController {


    @Resource
    private TaoCanService taoCanService;

    /**
     * 条件分页查询
     * @param page
     * @param size
     * @param map
     * @return
     */
    @PostMapping("/page/{page}/{size}")
    public Result page(@PathVariable("page")Integer page,
                       @PathVariable("size")Integer size,
                       @RequestBody Map<String,Object> map){

        return taoCanService.page(page,size,map);
    }


    @PostMapping("/add")
    public Result addTaoCan(@RequestBody TaocanVo taocanVo){
        System.out.println(taocanVo);
        return taoCanService.addTaoCan(taocanVo);
    }

    @GetMapping("/{id}")
    public Result getTaoCanById(@PathVariable("id")Integer id){
        return taoCanService.getById(id);
    }

    /**
     * 根据套餐id查询关联的菜品信息
     * @param taocanId
     * @return
     */
    @GetMapping("/dish/{taocanId}")
    public Result getTaocanDishByTid(@PathVariable("taocanId")Integer taocanId){
        return taoCanService.getTaoCanDishesByTid(taocanId);
    }

    /**
     * 修改套餐，根据套餐id
     * @param taocanVo
     * @return
     */
    @PutMapping("/update")
    public Result updateTaocan(@RequestBody TaocanVo taocanVo){
        return taoCanService.updateTaocan(taocanVo);
    }


    /**
     * 修改套餐售卖状态
     * @param status
     * @return
     */
    @GetMapping("/status/{id}/{status}")
    public Result changeStatus(@PathVariable("id")Integer id,@PathVariable("status")Integer status){
        return taoCanService.changeStatus(id,status);
    }


    /**
     * 根据id数组批量删除菜品
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public Result deleteDishes(@RequestBody Map<String, List<Integer>> map){
        List<Integer> ids = map.get("ids");
        return taoCanService.deleteTaocans(ids);
    }




}
